package com.cky.software.wubaihe.pay;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PayVersion1 {
//    注册的用户名和密码的预备字段
    public static String name="";
    public static String pwd="";
//    商品清单
    static Map<String,Object> shopMap=new HashMap<>();
//    购物车清单Map
    static Map<String,Object> payMap=new HashMap<>();
//    下单支付清单 Map
    static Map<String,Object>checkMap=new HashMap<>();

    public static void main(String[] args) {
        register();
        login();
        shopList();
        palList();
        check();
        result();
    }
//    1.注册
    public static  void register(){
        name="WU_BAIHE";
        pwd="123456";
        System.out.println("注册成功");
    }
//    2.登录
    public static void login(){
        String inputName="WU_BAIHE" ;
        String inputPwd="123456";

        if(inputName.equals(name)){
            System.out.println("用户存在");
            if(inputPwd.equals(pwd)){
                System.out.println("登录成功");
            }else{
                System.out.println("密码输入错误");
            }
        }else {
            System.out.println("用户不存在");
        }
    }
//    3.商品列表
    public static void shopList(){
        shopMap.put("苹果",16.5);
        shopMap.put("猪肉",30);
        shopMap.put("香蕉",17);
        shopMap.put("牛肉",43);
        System.out.println("商品列表："+shopMap);
    }
//    4.购物车列表
    public static void palList(){
        List<String>list=new ArrayList<>();

        for(Map.Entry<String,Object>keys:shopMap.entrySet()){
            if(keys.getKey().equals("苹果")){
                payMap.put(keys.getKey(),keys.getValue());
                list.add(keys.getKey());
            }else if(keys.getKey().equals("猪肉")){
                payMap.put(keys.getKey(),keys.getValue());
                list.add(keys.getKey());
            }
        }
        for (String s : list) {
            shopMap.remove(s);
        }
//        shopMap.remove(list.get(0));
//        shopMap.remove(list.get(1));

        System.out.println("购物车："+payMap);
        System.out.println("商品列表"+shopMap);
    }
//    5.下单支付方法
    public static void check(){
        List<String> list=new ArrayList<>();
        for(Map.Entry<String,Object>keys:payMap.entrySet()){
            if(keys.getKey().equals("猪肉")){
                checkMap.put(keys.getKey(),keys.getValue());
                list.add(keys.getKey());
            }
        }
//        通过获取List中的数据来删除PayMay中的数据
        payMap.remove(list.get(0));
        System.out.println("下单支付："+checkMap);
        System.out.println("购物车："+payMap);

    }
//    6.打印购物清单
    public static void result(){
        System.out.println("票据："+checkMap);
    }

}
